<!-- 用户信息 -->
<template>
  <div>
    <el-card shadow="never"
             body-style="padding: 20px;">
      <div class="ele-cell workplace-user-card">
        <div class="ele-cell-content ele-cell">
          <el-avatar :size="68"
                     :src="require('@/assets/user.png')"
                     style="background-color: #fff" />
          <div class="ele-cell-content">
            <h4 class="ele-elip">
              <span v-if="new Date().getHours() < 10">早安,</span>
              <span v-if="new Date().getHours() < 12 && new Date().getHours() > 10">上午好,</span>
              <span v-if="new Date().getHours() < 18 && new Date().getHours() > 12">下午好,</span>
              <span v-if="new Date().getHours() < 23 && new Date().getHours() > 18">晚上好,</span>
              {{ loginUser.nickname }} , 开始您一天的工作吧!
            </h4>
            <div class="ele-text-secondary ele-elip"
                 style="margin-top: 8px">
              <i class="el-icon-sunny"></i>
              <em>今天又是新的一天。</em>
            </div>

          </div>
          <el-button v-if="latestVersionBoolen"
                     style="margin: 0 10px"
                     plain
                     size="mini"
                     :loading="loading"
                     @click="versionUpload">下载小程序包</el-button>
        </div>
      </div>
    </el-card>
    <ele-modal width="680px"
               :visible="visible"
               :append-to-body="true"
               :close-on-click-modal="true"
               custom-class="ele-dialog-form"
               title="返回原因">
      <el-form ref="form"
               label-width="82px">

        <el-input type="textarea"
                  :rows="2"
                  resize="none"
                  :disabled="true"
                  v-model="signMsg">
        </el-input>

      </el-form>
      <template v-slot:footer>

        <el-button type="primary"
                   :loading="loading"
                   @click="save">
          确定
        </el-button>
      </template>
    </ele-modal>
  </div>
</template>

<script>
import {
  platformConfigDetail,
  platformSettingsModify
} from '@/api/platformSettings/index';
import {
  updateVersionApi,
  selectRenewInfo,
  fileDownload
} from '@/api/updateVersion/index';
// import { getAdminProfileData  } from '@/api/user/info';
export default {
  name: 'ProfileCard',
  computed: {
    // 当前登录用户信息
    loginUser () {
      return this.$store.state.user.info;
    }
  },
  data () {
    return {
      siteNumObject: '',
      // 当前版本
      currentVersion: '',
      //   最新版本
      latestVersion: '',
      //   标记
      sign: '',
      //   当前标记信息
      signMsg: '',
      latestVersionBoolen: false,
      //   到期时间
      endDate: '',
      loading: false,
      visible: false,
      form: {
        // 取平台的appid
        appid: '',
        // 取平台的域名
        realmName: '',

        softwareIdentifying: 'wjyk_massage',
        updateFlag: '1'
      },
      params: {
        softwareIdentifying: 'wjyk_massage',
        page: 1,
        limit: 10
      },
      //   当前总数
      total: null,
      //
      //   更新列表
      upDataList: [],
      //   日记更新列表
      logList: [],
      pcGzhUrl: '',
      versionUrl: '',
      // 表单数据
      userData: {
        order_count: 0,
        dai_kp_count: 0,
        tx_count: 0,
        use_yunvideo_count: 0,
        can_yunvideo_count: 0,
        use_video_count: 0,
        can_video_count: 0
      }
    };
  },
  activated () {
    this.init()
  },
  methods: {
    downAppCode () {
      window.open('/badmin/wjyk_bpdc.zip');
    },
    async init () {
      const res = await platformConfigDetail();
      this.form.appid = res.appid;
      this.form.id = res.id
      this.currentVersion = res.versionNumber;
      this.form.realmName = res.realmName;

      //   更新列表
      const upDataList = await selectRenewInfo(this.params);
      console.log(upDataList.empowerrenewMap);
      this.total = upDataList.empowerrenewMap.total;
      this.logList = upDataList.empowerrenewMap.rows;

      //查询是否具备更新能力
      const updateVersion = await updateVersionApi({
        updateFlag: 1
      });
      console.log(updateVersion);


      this.latestVersion = updateVersion.versionNumber;
      this.sign = updateVersion.sign;
      this.endDate = updateVersion.endDate;
      this.versionUrl = updateVersion.xcxZip;
      //   this.pcGzhUrl = updateVersion.pcGzh;
      //   this.versionUrl = updateVersion.msg;
      if (this.sign == '0') {
        this.visible = true
        this.signMsg = '未在站点授权，不支持更新版本';

      } else if (this.sign == '2') {
        this.visible = true
        this.signMsg = '授权已到期，不支持更新版本';
      } else if (this.sign == '3') {
        this.visible = true
        this.signMsg = '软件名称有误';
      } else if (this.sign == '4') {
        this.visible = true
        this.signMsg = '版本更新失败';
      }
      // 当前版本和最近版本 如果当前版本和最近版本一样那么不需要更新
      if (this.sign == '1') {
        this.latestVersionBoolen = true;
        // this.signMsg = '您已经是最新版了';
      } else {
        this.latestVersionBoolen = false;
        // this.signMsg = '版本需要更新';
      }
    },
    async versionUpload () {
      console.log(this.versionUrl)

      window.open(this.versionUrl, '_self');
      //   调用修改接口
      //   const res = await platformSettingsModify({
      //     versionNumber: this.latestVersion,
      //     id: this.form.id
      //   })
      //   console.log(res)

      //   this.loading = true;
      //   const res = await fileDownload({
      //     pcGzhUrl: this.pcGzhUrl,
      //     versionUrl: this.versionUrl,
      //     versionNumber: this.latestVersion
      //   });
      //   if (res) {
      //     this.loading = false;
      //     this.$message.success(res);
      //     // 修改当前的版本号

      //     const data = {
      //       versionNumber: this.latestVersion
      //     };
      //     // 刷新页面
      //   this.$router.go(0);
      //   }
    },
    // 确定并且退出登录页面
    save () {
      // 清除token
      localStorage.clear();
      sessionStorage.clear()
      this.$router.go(0);
    },
    upLoadZip () {
      console.log(this.versionUrl)
      window.open(this.versionUrl, '_self');
    }

  },

};
</script>

<style scoped>
.workplace-user-card .ele-cell-content {
  overflow: hidden;
}

.workplace-count-group {
  white-space: nowrap;
}

.workplace-count-item {
  padding: 0 5px 0 25px;
  box-sizing: border-box;
  display: inline-block;
  text-align: right;
}

.workplace-count-name {
  padding-left: 8px;
}

.workplace-count-num {
  font-size: 24px;
  margin-top: 6px;
}

@media screen and (max-width: 992px) {
  .workplace-count-item {
    padding: 0 5px 0 10px;
  }
}

@media screen and (max-width: 768px) {
  .workplace-user-card,
  .workplace-count-group {
    display: block;
  }

  .workplace-count-group {
    margin-top: 15px;
    text-align: right;
  }
}
</style>
